<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.js"> </script>
</head>
<body>
    
</body>
<script>
    // async也是异步变同步 只能在最近一个函数外执行
    async function show(){
        console.log('xxx');
        let xu = await $.ajax({url:'data.json'})
        return xu
    }
    let xp = show()
    xp.then((res)=>{
        console.log(1,res);
    }).catch((err)=>{
        console.log(2,err);
    })

    function Axios(url){
        return new Promise((resolve,reject)=>{
            $.ajax({
                url:url,
                success:(res)=>{
                    resolve(res)
                },
                error:(err)=>{
                    reject(err)
                }
            })
        })
    }

    //解决地狱回调的方法
    async function zai1(){
        try{
            let x1 = await Axios('data.json')
            console.log(x1);
            if(x1){
                let x2 = await Axios('data2.json')
                console.log(x2);
            }
        }
        catch{
            let x3 = await Axios('data3.json')
            console.log(x3);
        }
    }
    zai1()


    let abc = XMLHttpRequest()
</script>
</html>